package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.FamilyMember;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 * 
 * @author zhq
 * @date 2025-08-20
 */
@Api(tags = "老人家属管理")
@RestController
@RequestMapping("/member/user")
public class FamilyMemberController extends BaseController
{
    @Autowired
    private IFamilyMemberService familyMemberService;

    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login (@RequestBody UserLoginRequestDto userLoginRequestDto){
        LoginVo login = familyMemberService.login(userLoginRequestDto);
        return AjaxResult.success(login);
    }


    @ApiOperation("查询老人家属列表")
    @PreAuthorize("@ss.hasPermi('nursing:member:list')")
    @GetMapping("/list")
    public TableDataInfo<List<FamilyMember>> list(@ApiParam("老人家属查询条件") FamilyMember familyMember)
    {
        startPage();
        List<FamilyMember> list = familyMemberService.selectFamilyMemberList(familyMember);
        return getDataTable(list);
    }



   /* @ApiOperation("导出老人家属列表")
    @PreAuthorize("@ss.hasPermi('nursing:member:export')")
    @Log(title = "老人家属", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(@ApiParam(value = "老人家属查询条件") HttpServletResponse response, FamilyMember familyMember)
    {
        List<FamilyMember> list = familyMemberService.selectFamilyMemberList(familyMember);
        ExcelUtil<FamilyMember> util = new ExcelUtil<FamilyMember>(FamilyMember.class);
        util.exportExcel(response, list, "老人家属数据");
    }



    @ApiOperation("获取老人家属详细信息")
    @PreAuthorize("@ss.hasPermi('nursing:member:query')")
    @GetMapping(value = "/{id}")
    public R<FamilyMember> getInfo(@ApiParam("老人家属ID") @PathVariable("id") Long id)
    {
        return R.ok(familyMemberService.selectFamilyMemberById(id));
    }



    @ApiOperation("新增老人家属")
    @PreAuthorize("@ss.hasPermi('nursing:member:add')")
    @Log(title = "老人家属", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@ApiParam("老人家属信息") @RequestBody FamilyMember familyMember)
    {
        return toAjax(familyMemberService.insertFamilyMember(familyMember));
    }



    @ApiOperation("修改老人家属")
    @PreAuthorize("@ss.hasPermi('nursing:member:edit')")
    @Log(title = "老人家属", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam("老人家属信息") @RequestBody FamilyMember familyMember)
    {
        return toAjax(familyMemberService.updateFamilyMember(familyMember));
    }



    @ApiOperation("删除老人家属")
    @PreAuthorize("@ss.hasPermi('nursing:member:remove')")
    @Log(title = "老人家属", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@ApiParam("老人家属ID数组") @PathVariable Long[] ids)
    {
        return toAjax(familyMemberService.deleteFamilyMemberByIds(ids));
    }*/


}
